﻿package component.tree.util;

import component.tree.entity.Entity;
import component.tree.entity.Tree;

public class TreeUtil {
	public final static String SPLIT = ";";
	
	public static String getDivValue(Tree tree){
		String divValue = tree.getId() + SPLIT + tree.getParentId() + SPLIT + tree.getName() + SPLIT + tree.getType() + SPLIT + 
			tree.getLevel() + SPLIT + tree.getPath() + SPLIT + tree.getIsLastStr() + SPLIT + tree.getOtherValue();
		return divValue;
	}
	
	public static Tree getTree(Tree tree,String divValue){
		String[] valueArr = divValue.split(SPLIT);
		tree.setId(valueArr[0]);
		tree.setParentId(valueArr[1]);
		tree.setName(valueArr[2]);
		tree.setType(Integer.parseInt(valueArr[3]));
		
		tree.setLevel(Integer.parseInt(valueArr[4]));
		tree.setPath(valueArr[5]);
		tree.setIsLastStr(valueArr[6]);
		
		return tree;
	}
	
	public static Object getObject(String className) {
		Object obj = null;
	
		try {
			obj = Class.forName(className).newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		return obj;
	}
}
